mp2ids = [:]

new File (args[0]).splitEachLine("\t") { splits ->
  if ( splits.size() > 1 ) {
    if (!mp2ids.containsKey(splits[0].trim())) {
      mp2ids[splits[0].trim()] = new TreeSet<String>()

      splits [1..-1].each { t ->
        if ( !t.startsWith("PATO:")) mp2ids[splits[0].trim()].add(t)
      }

    } else println "double def for mp: " + splits[0].trim()
  } 
}

new File (args[1]).splitEachLine("\t") { splits ->
  if ( splits.size() > 1 ) {
    if ( mp2ids.containsKey( splits[0].trim() ) ) mp2ids[splits[0].trim()].addAll(splits[1..-1])
  }
}

mp2ids.each { println it.key + "\t" + it.value.join("\t")}